#include <set>

using namespace std;

struct TreeNode
{
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};

class Solution
{
public:
    void CountNum(TreeNode *root, set<int> &st)
    {
        if (root == nullptr)
        {
            return;
        }
        else
        {
            st.insert(root->val);
            CountNum(root->left, st);
            CountNum(root->right, st);
        }
    }
    int numColor(TreeNode *root)
    {
        set<int> num;
        CountNum(root, num);
        return num.size();
    }
};